# -*- coding: utf-8 -*-
import scrapy


class GnhjSpider(scrapy.Spider):
    name = 'gnhj'
    allowed_domains = ['www.youhui.com']
    start_urls = ['https://m.smzdm.com/youhui/']

    def parse(self, response):
        # response就是我们要请求的网页信息，我们直接可以取
        sp_list = response.xpath("//div[@class='wrap-content']/ul/li")
        for sj_list in sp_list:
            # 获取每个商品的名字
            name = sj_list.xpath("./a/div/div[2]/div[1]/text()").extract()[0]
            # 获取每个商品的价格
            # price = sj_list.xpath("./a/div/div[2]/div[2]/text()").extract()[0].replace("元", " ")
            price = sj_list.xpath("./a/div/div[2]/div[2]/text()").extract()[0]
            # 获取每个商品的平台
            pt = sj_list.xpath("./a/div/div[2]/div[3]/div[1]/span/span[1]/text()").extract()[0]
            # 获取每个商品的发布时间
            up_time = sj_list.xpath("./a/div/div[2]/div[3]/div[1]/span/span[2]/text()").extract()[0]
            # print(price, up_time)

            yield {
                "商品名": name,
                "价格": price,
                "平台": pt,
                "发布时间": up_time
            }
